import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
import vitePluginImp from 'vite-plugin-imp'
import path from 'path'

export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd())
  const { VITE_APP_API_URL, VITE_APP_API_PORT } = env
  return {
    plugins: [
      react(),
      vitePluginImp({
        libList: [
          {
            libName: "antd",
            style: (name) => `antd/es/${name}/style`,
          },
        ],
      })
    ],
    base: './',
    resolve: {
      alias: {
        '@': path.resolve(__dirname, 'src')
      }
    },
    server: {
      proxy: {
        '/proxywifi': {
          // target: 'http://127.0.0.1:3000',
          target: `${VITE_APP_API_URL}:${VITE_APP_API_PORT}`,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/proxywifi/, '')
        }
      }
    }
  }
})
